package com.example.jf.jfapp;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * Created by jf on 2017/7/26.
 */

public class WelcomeActivity extends AppCompatActivity {

    Handler handler = new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        handler.postDelayed(runnable, 2000);

        TextView version = (TextView) findViewById(R.id.version);
        version.setText(getAppInfo());

        // TODO: 2017/7/6
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
        //附近的人，可能会用到这个！
      //  SDKInitializer.initialize(getApplicationContext());


    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            //暂时不需要判断！
//            boolean isLogin = AppConfigUtils.getInstance().getLoginStatu(WelcomeActivity.this);
//            if (isLogin) {
//                startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
//                finish();
//            } else {
//                startActivity(new Intent(WelcomeActivity.this, StatuListActivity.class));
                startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                finish();
            }
     //   }
    };

    @Override
    protected void onDestroy() {
        handler.removeCallbacks(runnable);
        super.onDestroy();
    }

    /**
     * 获取版本号
     * @return
     */
    private String getAppInfo() {
        try {
            String pkName = this.getPackageName();
            String versionName = this.getPackageManager().getPackageInfo(
                    pkName, 0).versionName;
            return versionName;
        } catch (Exception e) {
        }
        return null;
    }
}
